<div ng-include="sys_html('common/_header')"></div>
<style>
.cartmode{
	bottom: 2.5rem
}
.cartmode-backpage{
	bottom: 4.3rem
}
.fui-number .minus:before, .fui-number .plus:before {
	border-left: 0 solid #d9d9d9;
}
.fui-number .minus:after, .fui-number .plus:after {
	border-right: 0 solid #d9d9d9;
}
.fui-number:before {
	border-top: 0 solid #d9d9d9;
}
.fui-number:after {border-top: 0 solid #d9d9d9;}
.fui-number .num {
	color:#666;
}
.fui-number .num {
	color:#666;
}
.fui-number.small {
	height: 1.2rem;
	width: 3.6rem;
	line-height: 1.2rem;
}
.fui-number .minus, .fui-number .plus {
	z-index:0;
}
.fui-number.small .minus{
	color: {{main.syscolor || '#63BE72'}};
	padding-top:1px;
	border: 1px solid {{main.syscolor || '#63BE72'}};
	border-radius:50%;
}
 .fui-number.small .plus {
	color: #fff;
	padding-top:1px;
	background: {{main.syscolor || '#63BE72'}};
	border: 1px solid {{main.syscolor || '#63BE72'}};
	border-radius:50%;
}
.jy2-headertop {position: absolute; min-height: 100%;padding-top:0.3rem;padding-bottom:0.3rem;margin-top:-2rem;border-top-right-radius:1rem;border-top-left-radius:1rem;}
.fui-header a.back:before {
	border-color: #fff
}
.fui-header:after {
	border-bottom: 0 solid #D9D9D9;
}
.fui-navbar .cartbtn {padding-right:0.3rem;background:#fff;opacity:1}
.fui-navbar .buybtn  {padding-left:0.3rem;background:#fff}
.fee-tag-nav, .fee-tagup-nav, .fee-disabled-nav {border-radius:1rem;height:2rem;line-height:1.95rem;color:#fff;width:100%;font-weight:400;font-size:0.7rem;margin:0.2rem 0;padding:0 0.2rem;text-align:center}
.fee-tagup {background:{{main.syscolor || 'red'}};color:#fff;width:auto;font-weight:400;font-size:0.55rem}
.fee-tag-nav {background:{{main.syscolor || 'red'}}; opacity: 0.58;}
.fee-tagup-nav {background:{{main.syscolor || 'red'}};}
.fee-disabled-nav {background:#bbb;color:#fff;}	
</style>
<div class='fui-page  fui-page-current member-cart-page'>
	<div class="topbg" style="position: relative;text-align:center;width:100%;height:4.5rem;background: {{main.syscolor || '#7c1cc9'}};">
			<div class="fui-header" style="background:none">
				<div class="fui-header-left">
					<a class="back" style="color:#fff" href="javascript:" ng-click="goback()"></a>
				</div>
				<div class="title bold" style="font-size:1rem;color:#fff">我的购物车</div>
				<div class="fui-header-right" style="padding-right:0.5rem;color:#fff">
						<a class="btn-edit" style="color:#ddd" ng-click="toogle(pagedata,'show_edit')">{{ifelse(pagedata.show_edit,'完成','编辑')}}</a>
				</div>
			</div>
	</div>
	<div class='fui-content jy2-headertop cart-list'>
		<div ng-if="pagedata.shopset.open_tips==1" class="tips tips-yellow">
			<i class="fa fa-bullhorn"></i> [<red>温馨提示</red>]：{{pagedata.shopset.tips}}
		</div>
		<div id="cart_container">
		<div ng-if="pagedata.cartlist.length<=0 && pagedata.loaded" class="content-empty">
			<img src="../addons/jy_weishop/images/nogoods.png" style="width: 6rem;margin-bottom: .5rem;"><br/><p style="color: #999;font-size: .75rem">您的购物车中没有商品哦！</p><br/>
			<a href="javascript:;" ng-click="access_json(main.menus[0].action || 'jy_weishop/index/')" class='btn btn-sm btn-danger-o external'style="border-radius: 100px;width:  7rem;font-size: .75rem">去首页逛逛吧</a>
		</div>
		<div ng-if="pagedata.cartlist.length>0" class="fui-list-group" id="container" style="background:none;height:1200px;margin-top: 0;">
			<div ng-repeat="g in pagedata.cartlist" class="fui-list goods-item align-start">
				<div class="fui-list-media " ng-show="!pagedata.show_edit">
					<input ng-if="g.canbuy && !g.outtype" type="checkbox" ng-checked="g.selected==1" ng-click="pagedata.toogle_select(g)" name="checkbox" class="fui-radio fui-radio-danger cartmode check-item choose_goods"/>
					<input ng-if="!g.canbuy || g.outtype" type="checkbox" disabled="disabled" class="fui-radio fui-radio-danger cartmode check-item"/>
				</div>
				<div class="fui-list-media" ng-show="pagedata.show_edit">
				   <input type="checkbox" name="checkbox" ng-checked="pagedata.del.indexOf(';'+g.id+';')>=0" ng-click="duoxuans(g.id,pagedata,'del')" class="fui-radio fui-radio-danger edit-item del_history"/>
				</div>

				<div class="fui-list-media image-media">
					<a href="javascript:;" ng-click="pagedata.getgoodsdetail(g.goodsid);">
						<img ng-src="{{tomedia(g.image) || '../core/resource/images/nopic.jpg'}}" class="">
					</a>
				</div>
				<div class="fui-list-inner">
					<a href="javascript:;" ng-click="pagedata.getgoodsdetail(g.goodsid);">
						<div class="subtitle">
							<span ng-if="g.type==4" class='fui-label fui-label-danger'>批发</span>
							<span ng-if="g.discounttype>0 && g.isnodiscount ==0" class='fui-label fui-label-danger'>折扣</span>
							<div ng-if="g.seckillprice>0" class="fui fui-label fui-label-danger">{{g.seckilltag}}</div>
							{{g.title}}
						</div>
					</a>
						<div class="subtitle cart-option" style="line-height:1">
							<div class="choose-option" onclick="$('#showspec').modal();">{{g.optiontitle ||'默认'}}</div>
							<span class="num bold">x {{g.total}} /{{g.unit || '件'}} <span ng-if="g.weight!='0.00'">（{{g.weight}}kg）</span></span>
							<span ng-if="g.canbuy && g.outtype" style="margin-right:-1rem;min-height:1.2rem;color:red;font-size:0.55rem;font-weight:400;">
								{{g.outnumtitle}}
							</span>
						</div>
					<div ng-if="g.active && g.active.title" class="red" style="line-height:1">
							{{g.active.title}}
					</div>
					<div class='price'>
						<span class="bigprice text-danger">￥<span class='marketprice'>{{g.price}}</span></span>
						<div ng-if="g.canbuy" class="fui-number small">
								<div class="minus" ng-click="pagedata.minus($index)"><i class="icon icon-subtract" style="font-size:0.7rem"></i></div>
								<input class="num shownum" type="text" ng-model="g.total" style="width:50px" ng-change="pagedata.refresh()"/>
								<div ng-if="g.kucun>=g.total" class="plus" ng-click="pagedata.plus($index)"><i class="icon icon-tianjia" style="font-size:0.7rem"></i></div>
								<div ng-if="g.kucun<g.total" class="plus" style="color:#ddd"><i class="icon icon-tianjia" style="font-size:0.7rem"></i></div>
						</div>
						<div ng-if="!g.canbuy" class="bold red">
							{{g.nobuytitle}}
						</div>
					</div>
			</div>
		</div>
		</div>
	</div>
	<div id="footer_container">
	<div ng-if="pagedata.cartlist.length>0 && !pagedata.show_edit" ng-class="{'fui-footer cartmode':1, 'cartmode-backpage':pagedata.is_backpage && main.closebackpage!=1}">
		<div class="fui-list noclick">
			<div class="fui-list-media">
				<label class="checkbox-inline checkall" style="margin-right:.8rem">
					<input type="checkbox" name="checkbox" class="fui-radio fui-radio-danger "  onclick="var ck = this.checked;$('.choose_goods').each(function(){if(this.checked != ck){$(this).click();}});"/>&nbsp;全选
				</label>
			</div>
			<div class="fui-list-inner">
				<div class='subtitle l' style="font-size:0.7rem;padding-bottom:0.15rem">合计:<span class="bigprice" style="font-weight:600"> ￥</span><span class='totalprice  bigprice' style="font-weight:600;">{{pagedata.totalprice}}</span></div>
			</div>
			<div class='fui-list-angle' style="padding-left:2px;padding-right:0.5rem">
				<div ng-click="pagedata.check_buy()" ng-class="{'fee-disabled-nav':pagedata.total<=0,'fee-tag-nav':pagedata.total>0}">
						结算(<span class='total'>{{pagedata.total}}</span>)
				</div>
		</div>
		</div>
	</div>
	<div ng-class="{'fui-footer cartmode':1, 'cartmode-backpage':pagedata.is_backpage && main.closebackpage!=1}" ng-show="pagedata.show_edit">
		<div class="fui-list noclick">
			<div class="fui-list-media">
				<label class="checkbox-inline editcheckall"><input type="checkbox" name="checkbox" class="fui-radio fui-radio-danger " onclick="var ck = this.checked;$('.del_history').each(function(){if(this.checked != ck){$(this).click();}});" />&nbsp;全选</label>
			</div>
			<div class='fui-list-angle'>				
				<div class="fee-tag-nav" ng-click="post({},'del','del='+pagedata.del)">删除</div>
			</div>
		</div>
	</div>
	</div>
</div>
<div ng-include="sys_html('shop/_goodsdetail')"></div>
<script>
if(scope.main.menus && scope.main.menus.length>0){	
	for(var i=0;i<scope.main.menus.length;i++){
		if(scope.main.menus[i].action=='jy_weishop/member.cart/'){
			scope.main.menus[i].nums=scope.pagedata.cartnums
		}
	}
}
scope.pagedata.cartlist=[];
scope.pagedata.get_list=function(first){
			if(first){
				//初次加载
				scope.pagedata.page=1;
				scope.pagedata.cartlist=[];
				scope.pagedata.loaded=false;
				$('#loaded').hide();
			}else if(!scope.pagedata.page){
				scope.pagedata.page=1;
			}else{
				scope.pagedata.page++;
			}
			if(scope.pagedata.loaded){
				return;
			}
			if(scope.pagedata.loading){
				return;
			}else{
				scope.pagedata.loading=true;
			}
			$('#loading').show();$('#loadmore').hide();
			var query='page='+scope.pagedata.page;
			if(scope.page.query){
				query+='&'+scope.page.query;
			}
			var more_query=scope.made_query(scope.pagedata.params);
			if(more_query){
				query+='&'+more_query;
			}
			scope.get_data(function(res){
				if(res.list.length==0){
					scope.pagedata.loaded=true;
					scope.$evalAsync();
					scope.pagedata.loading=false;
					$('#loading').hide();
					$('#loaded').show();
					if(scope.pagedata.cartlist.length==0){
						$('#no_goods').show();
					}
					return;
				}
				res.list.forEach(function(v){
					scope.pagedata.cartlist.push(v);
				});
				scope.pagedata.loading=false;
				scope.pagedata.refresh();
				scope.$apply();
				$('#loading').hide();
				$('#loadmore').show();
				
			},'',{'op':'getlist','query':query});
}
//首次加载
scope.pagedata.get_list(true);
//滑到页面底部时加载下一页
scope.pagedata.scroll_bottom=function(){
	if(!scope.pagedata.loaded && !scope.pagedata.loading){
		scope.pagedata.get_list();
	}
}
//减少
scope.pagedata.minus=function(index){
	var cart=scope.pagedata.cartlist[index]
	scope.post_json('jy_weishop/member.cart/minus/',{'id':cart.id},function(){
				if(cart.total==1){
					scope.pagedata.cartlist.splice(index,1);
				}
				cart.total--;
				if(cart.outtype==1 && cart.total + cart.order_goodscount<=cart.usermaxbuy){
					cart.outtype=false;
				}
				if(cart.outtype==2 && cart.total<=cart.kucun){
					cart.outtype=false;
				}
				if(cart.outtype==4 && cart.total<=cart.maxbuy){
					cart.outtype=false;
				}
				if(cart.outtype==5 && cart.total<=cart.active.maxnum){
					cart.outtype=false;
				}
				scope.pagedata.cart=cart;
				scope.pagedata.refresh();
				if(cart.total==0){
					scope.message('删除成功！');
				}else{
					scope.message('减少成功！');
				}
				scope.$evalAsync();
	})
}
//增加
scope.pagedata.plus=function(index){
	var cart=scope.pagedata.cartlist[index]
	if(cart.kucun<=cart.total){
		scope.message('超库存，不能再加了！');
		return false;
	}
	scope.post_json('jy_weishop/member.cart/plus/',{'id':cart.id},function(res){
			if(res=='success'){
				cart.total++;
				if(cart.outtype==3 && cart.total>=cart.minbuynum){
					cart.outtype=false;
				}
				scope.message('添加成功！');
				scope.pagedata.refresh();
				scope.$evalAsync();
			}else{
				scope.message('添加失败:'+res);
			}
	});
}
//选择
scope.pagedata.toogle_select=function(cart){
	var selected=cart.selected==1?0:1;
	var params={
		data:{'id':cart.id,'selected':selected},
		op:'select',
		callback:function(res){
			cart.selected=selected;
			scope.pagedata.refresh();
			scope.$evalAsync();
		}
	};
	scope.post_json(params);
}
//刷新总数和总价
scope.pagedata.refresh=function(){
	var total=0,totalprice=0.00;
	angular.forEach(scope.pagedata.cartlist,function(cart){
		if(cart.selected==1){
			total+=parseInt(cart.total);
			totalprice+=cart.total*cart.price;
		}
	});
	var totalprice = totalprice.toString(); //将数字转换为字符串
	var pos_decimal = totalprice.indexOf('.'); //小数点的索引值
	 // 当整数时，pos_decimal=-1 自动补0  
	if (pos_decimal < 0) {  
			pos_decimal = totalprice.length;  
			totalprice += '.';  
	}

	// 当数字的长度< 小数点索引+2时，补0  
	while (totalprice.length <= pos_decimal + 2) {  
			totalprice += '0';  
	}  
	scope.pagedata.total=total;
	scope.pagedata.totalprice=totalprice;
}
scope.pagedata.check_buy=function(){
	scope.get('jy_weishop/member.cart/check_buy/',function(res){});
}
</script>

</div>
<div ng-include="sys_html('common/_menu')"></div>
<div ng-include="sys_html('common/_footer')"></div>